package model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class ConnectionSingleton {

	private static ConnectionSingleton instance;
	private SessionFactory sess_fact;
	
	public SessionFactory getSess_fact() {
		return sess_fact;
	}

	public Transaction getT() {
		return t;
	}

	public Session getS() {
		return s;
	}

	private Transaction t;
	private Session s;
	
	private ConnectionSingleton() {
		Configuration configuration = new Configuration();
		configuration.configure();
		sess_fact = configuration.buildSessionFactory();
		s = sess_fact.getCurrentSession();
	}
	
	public static ConnectionSingleton getInstance() {
		if(instance == null){
			instance = new ConnectionSingleton();
		}
		return instance;
	}

	public void beginTransaction() {
		// TODO Auto-generated method stub
		s = sess_fact.getCurrentSession();
		t =  s.beginTransaction();
	}

}
